home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 29N554 (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  1.9 KB  |  54 lines

  1. package com.sun.java.swing.text;
  2.  
  3. import com.sun.java.swing.AbstractAction;
  4. import com.sun.java.swing.Action;
  5. import java.awt.event.ActionEvent;
  6. import java.util.Enumeration;
  7. import java.util.EventObject;
  8. import java.util.Hashtable;
  9.  
  10. public abstract class TextAction extends AbstractAction {
  11.    public TextAction(String name) {
  12.       super(name);
  13.    }
  14.  
  15.    public static final Action[] augmentList(Action[] list1, Action[] list2) {
  16.       Hashtable h = new Hashtable();
  17.  
  18.       for(int i = 0; i < list1.length; ++i) {
  19.          Action a = list1[i];
  20.          String value = (String)a.getValue("Name");
  21.          h.put(value != null ? value : "", a);
  22.       }
  23.  
  24.       for(int i = 0; i < list2.length; ++i) {
  25.          Action a = list2[i];
  26.          String value = (String)a.getValue("Name");
  27.          h.put(value != null ? value : "", a);
  28.       }
  29.  
  30.       Action[] actions = new Action[h.size()];
  31.       int index = 0;
  32.  
  33.       for(Enumeration e = h.elements(); e.hasMoreElements(); actions[index++] = (Action)e.nextElement()) {
  34.       }
  35.  
  36.       return actions;
  37.    }
  38.  
  39.    protected final JTextComponent getFocusedComponent() {
  40.       return JTextComponent.getFocusedComponent();
  41.    }
  42.  
  43.    protected final JTextComponent getTextComponent(ActionEvent e) {
  44.       if (e != null) {
  45.          Object o = ((EventObject)e).getSource();
  46.          if (o instanceof JTextComponent) {
  47.             return (JTextComponent)o;
  48.          }
  49.       }
  50.  
  51.       return this.getFocusedComponent();
  52.    }
  53. }
  54.